import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';

@Component({
  selector: 'app-input-group',
  templateUrl: './input-group.component.html',
  styles: [
    `
      .aui-select-right {
        padding-right: 0;
      }

      ::ng-deep.aui-select-right > .lv-input-after::before {
        margin-right: 0;
      }

      .aui-select-left {
        padding-left: 0;
      }

      .aui-inner-select {
        width: 65px;
      }

      ::ng-deep.aui-select-left > .lv-input-before::after {
        margin-left: 0;
      }

      ::ng-deep.aui-inner-select > .lv-select-wrapper {
        border: none;
        padding: 0;
      }

      ::ng-deep.aui-select-storage > .lv-input-prefix {
        left: 0;
      }

      .aui-storage-select {
        width: 114px;
      }

      .aui-split {
        width: 1px;
        height: 20px;
        margin-left: -8px;
        background-color: #e6e6e6;
      }

      .aui-icon {
        color: #4d4d4d;
      }

      .lv-input-group.lv-input-group-disabled {
        .aui-icon {
          color: rgba(77, 77, 77, 0.5);
        }
      }

      lv-form-control {
        width: 100%;
      }
    `,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class InputGroupComponent implements OnInit {
  disabled = false;
  loading = true;

  btnText = 'Disable';

  inputValue;

  limit = 25;

  bandwidthValue = '350';

  areaCode = '+86';
  areaCodeOptions = [{ label: '+86', value: '+86', isLeaf: true }];

  unit = 'MB';
  unitOptions = [{ label: 'MB', value: 'MB', isLeaf: true }];

  storageName = 'LUN Name';
  storageNameOptions = [{ label: 'LUN Name', value: 'LUN Name', isLeaf: true }];

  ngOnInit(): void {
    this.inputValue = new FormControl('', [Validators.maxLength(this.limit)]);

    this.inputValue.markAsDirty();
    this.inputValue.updateValueAndValidity();
  }

  change() {
    this.disabled = !this.disabled;

    if (this.disabled) {
      this.btnText = 'Enable';
    } else {
      this.btnText = 'Disable';
    }
  }
}
